package com.waffles.mbta.tracker;

import java.util.List;

import android.os.Bundle;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class ViewRoute extends MapActivity {
	MapView mapView;
	BusStopOverlay stopOverlay;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.view_route);
		
        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        
        MapController controller = mapView.getController();
        
        List<Overlay> mapOverlays = mapView.getOverlays();
        
        stopOverlay = new BusStopOverlay(this.getResources().getDrawable(R.drawable.a_pin));
        
        List<OverlayItem> stops = RouteInfo.getRouteInfo(getIntent().getExtras().getString("text"));

        int maxLat = -999999999, minLat = 999999999, maxLon = -999999999, minLon = 999999999;
        for(OverlayItem stop : stops) {
        	stopOverlay.addOverlay(stop);
        	GeoPoint point = stop.getPoint();
        	int lat = point.getLatitudeE6();
        	int lon = point.getLongitudeE6();
        	if(lat < minLat) minLat = lat;
        	if(lon < minLon) minLon = lon;
        	if(lat > maxLat) maxLat = lat;
        	if(lon > maxLon) maxLon = lon;
        }
        
        int latSpan = maxLat - minLat;
        int lonSpan = maxLon - minLon;
        controller.setCenter(new GeoPoint(latSpan/2 + minLat, lonSpan/2 + minLon));
        controller.zoomToSpan((int)(latSpan*1.5), (int)(lonSpan*1.5));

        mapOverlays.add(stopOverlay);
    }

	@Override
	protected boolean isRouteDisplayed() {
		return false;
	}

}
